package com.oitsm.mo.dao;

import java.util.List;

import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.oitsm.commons.dao.BaseDaoImpl;
import com.oitsm.mo.entity.Node;

/**
 * 节点Dao 实现类
 * @author Arab Runner
 * Jun 25, 2011 12:09:40 PM
 */
@Repository
public class NodeDaoImpl extends BaseDaoImpl implements NodeDao {
	
	/**
	 * 保存一个节点
	 * @param n
	 * @return
	 */
	public Long addNode(Node n){
		this.getSession().save(n);
		return n.getId();
	}
	
	/**
	 * 修改节点
	 * @param n
	 */
	public void updateNode(Node n){
		this.getSession().save(n);
	}
	
	/**
	 * 删除多个节点
	 * @param ids
	 */
	public void removeNode(List<Long> ids){
		StringBuilder sqlStr = new StringBuilder();
		sqlStr.append("delete from node n where n.id in (");
		for(int i=0;i<ids.size();i++){
			if(i!=0){
				sqlStr.append(",");
			}
			sqlStr.append(ids.get(i));
		}
		sqlStr.append(")");
		
		SQLQuery sql = this.getSession().createSQLQuery(sqlStr.toString());
		sql.executeUpdate();
	}
	
}
